#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005];
long long ans;
bool b[1000005];
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>T;
	while (T--){
		scanf("%d",&n);
		memset(b,0,sizeof (b));
		ans=0;
		for (int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for (int i=1;i<=n;i++){
			if (b[a[i]]==0){
				b[a[i]]=1;
			}else{
				ans+=a[i];
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
